<template>
	<view class="container">
		<tui-list-cell :hover="false" :lineLeft="false">
			<view class="tui-cell-input">
				<input :value="old_password" placeholder="请输入原始登录密码" placeholder-class="tui-phcolor" type="password" :auto-focus="true" :focus="true" maxlength="40" @input="inputOldPassword" />
			   <icon type="clear" :size="14" color="#bfbfbf" v-show="old_password" @tap="clearOldPasswordInput"></icon>
			</view>
		</tui-list-cell>
		<tui-list-cell :hover="false" :lineLeft="false">
			<view class="tui-cell-input">
				<input :value="password" placeholder="请输入新的登录密码" placeholder-class="tui-phcolor" type="password" :auto-focus="true" :focus="true" maxlength="40" @input="inputPassword" />
			   <icon type="clear" :size="14" color="#bfbfbf" v-show="password" @tap="clearPasswordInput"></icon>
			</view>
		</tui-list-cell>
		<tui-list-cell :hover="false" :lineLeft="false">
			<view class="tui-cell-input">
				<input :value="comf_password" placeholder="请再次输入登录密码" placeholder-class="tui-phcolor" type="password" :auto-focus="true" :focus="true" maxlength="40" @input="inputComfPassword" />
			   <icon type="clear" :size="14" color="#bfbfbf" v-show="comf_password" @tap="clearComfPasswordInput"></icon>
			</view>
		</tui-list-cell>
		<view class="tui-btn-box">
			<tui-button shadow height="88rpx" shape="circle" type="danger" @click="savePayPassword()">确定</tui-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				password:'',
				old_password:'',
				comf_password:'',
			}
		},
		onShow() {
			this.tui.haslogin();
			if(this.tui.isLogin()){
				this.userinfo = this.tui.getUserInfoData();
			}
		},
		methods: {
			inputOldPassword(e) {
				this.old_password = e.detail.value;
			},
			clearOldPasswordInput() {
				this.old_password = '';
			},
			inputPassword(e) {
				this.password = e.detail.value;
			},
			clearPasswordInput() {
				this.password = '';
			},
			inputComfPassword(e) {
				this.comf_password = e.detail.value;
			},
			clearComfPasswordInput() {
				this.comf_password = '';
			},
			savePayPassword(){
				let token = this.tui.getToken();
				
				if(this.password!=this.comf_password){
					this.tui.toast('两次密码不一致');
					return;
				}
				let datas={
					token:token,
					up_type:3,
					old_password:this.old_password,
					new_password:this.password,
				};
				let password=this.tui.request('user','post',datas,1000,1,'','modifyPwd');
				Promise.resolve(password).then((value)=>{
				   if(value.code==200){
				   	this.tui.toast(value.message);
				   }else{
				   	this.tui.toast(value.message);
				   }
				})
			}
		}
	}
</script>

<style lang="scss">
.container {
	padding-top: 20rpx;
	.tui-cell-input {
		width: 100%;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		
		input {
			flex: 1;
			padding-left: $uni-spacing-row-base;
		}
	}
	.tui-btn-box {
		padding: 40rpx 30rpx 10rpx 30rpx;
		box-sizing: border-box;
	}
}
</style>
